layui.config({
    base: "static/layui/module/"
}).extend({
    dynamicCondition: 'dynamicCondition/dynamicCondition'
}).use(['form', 'layer', 'jquery', 'table', 'laydate', 'upload', 'dynamicCondition'], function () {
    var form = layui.form,
        layer = layui.layer,
        laypage = layui.laypage,
        $ = layui.jquery,
        table = layui.table,
        upload = layui.upload,
        laydate = layui.laydate,
        dynamicCondition = layui.dynamicCondition;

    let dataFields = object.dataFields;

    let dc = dynamicCondition.create({
        fields: dataFields
        ,tableId: "table"
        ,conditionTextId: "#findMsg"
        ,type: "complex"
        ,requestDataType: "json"
        ,counts: 10
        ,queryCallBack: function (requestData) {
        }
        ,afterOpen: function (_dc) {
            top_dc = _dc;
        }
    });

    dc.setCondition([["sale_order_detail_id","equal",condition]]);

    object.cols[0].type = "radio";

    table.render({
        elem: '#table'
        ,title: '列表'
        ,url: '/manage/common/list/settle_order_master_new'
        ,where: dc.buildRequestData()
        ,method: 'post'
        ,height: 'full-60'
        ,page: true //开启分页
        ,limit: 20
        ,limits: [20, 30, 40, 50, 60, 70, 80, 90, 100]
        ,loading: true
        ,cols: [object.cols]
        ,toolbar:'#tableToolbar'
        ,defaultToolbar: ['filter']
        ,text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        }
    });

    table.on('toolbar(table)', function(obj) {
        switch (obj.event) {
            case'nullify':
                let data =table.checkStatus('table').data;
                if (data.length === 0){
                    layer.msg("请先选择一条要结算的数据",{icon: '2'});
                    return;
                }
                layer.confirm('确定作废?', {icon: 3, title: '提示'}, function (index) {
                    $.post('manage/sale_order/settle_nullify',{id: data[0].id},function (d){
                        if(d.code == "200"){
                            layer.msg("结算作废成功",{icon: '1'},function () {
                                location.reload();
                            });
                        }else{
                            layer.alert("结算作废失败，"+d.msg,{icon: '2'});
                        }
                    })
                });
                break;
        }
    });

})